package com.openwater;

import java.util.List;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ConfigurationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private String TAG = "mainAct";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // initWeather();
        setContentView(R.layout.activity_main);
        Button dosomething = (Button) findViewById(R.id.btn_dosomsthing);
        dosomething.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), AppListActivity.class);
                startActivity(intent);
                finish();
            }
        });
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        // WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // if (detectOpenGLES20()) {
        // setContentView(new MySurfaceView(getApplicationContext()));
        // } else {
        // finish();
        // }
    }

    private void initWeather() {
        setContentView(R.layout.weather);
        // TextView weatherAddress = (TextView)
        // findViewById(R.id.weather_address);
        // ImageView weatherIcon = (ImageView) findViewById(R.id.weather_image);
        TextView tempReal = (TextView) findViewById(R.id.temp_real);
        tempReal.setTextColor(Color.BLUE);
        tempReal.setText(Html.fromHtml("13&#176;"));
        TextView tempMin = (TextView) findViewById(R.id.temp_min);
        tempReal.setTextColor(Color.BLUE);
        tempMin.setText("min:" + 12);
        TextView tempMax = (TextView) findViewById(R.id.temp_max);
        tempReal.setTextColor(Color.BLUE);
        tempMax.setText("max:" + 25);
    }

    public Intent getLauncherIntent() {
        Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);
        PackageManager packageManager = getPackageManager();
        List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        Intent intent2 = null;
        for (ResolveInfo resolveInfo : resolveInfos) {
            if (!getPackageName().equals(resolveInfo.activityInfo.packageName))
            // if this activity is not in our activity (in other words,
            // it's another default home screen)
            {
                intent2 = packageManager
                        .getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
            }
            Log.d(TAG, resolveInfo.toString());
        }
        return intent2;
    }

    private boolean detectOpenGLES20() {
        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        return (info.reqGlEsVersion >= 0x20000);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
